<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <title>完美校园JSAPI测试</title>
    <!-- 定义js方法-->
    <script src="wmxy-js-api.js"></script>
    <script>

    </script>
</head>
<body style="padding-bottom: 20pt">
<div style="display: flex;flex-direction: row;align-items: center">
    <h3>完美校园JSAPI测试</h3>
    <a style="margin-left: 20px" href="javascript:location.reload()"><h5>刷新</h5></a>
</div>


<br/><br/>

<input type="button" value="获取设备信息" onclick="getDeviceInfo()"/>
<script>
    function getDeviceInfo() {
        wanxiao.getDeviceInfo(function (result) {
            alert(result);
        })
    }
</script>

<br/><br/>


<input type="button" value="定位" onclick="jsGeLocationPosition()"/>
<label id="wz"></label>
<script>
    function jsGeLocationPosition() {
        var wz = document.getElementById("wz");
        wanxiao.getLocation(function (result) {
            wz.innerHTML += "<br/>" + JSON.stringify(result);
        });
    }
</script>

<br/><br/>

<input type="button" value="认证中心验证码" onclick="getPageCredentials()"/>
<script>
    function getPageCredentials() {
        wanxiao.getPageCredentials(function (result) {
            alert(result);
        })
    }
</script>
<br/><br/>

<input type="button" value="ISBN扫描" onclick="isbnScan()"/>
<label id="isbn"></label>
<script>
    function isbnScan() {
        wanxiao.isbnScan(function (result) {
            isbn.innerText = result;
        })
    }
</script>
<br/><br/>

<input type="button" value="获取头像" onclick="jsGetUserGravatar()"/>
<br>
<label id="pic_url" style="max-width: 300px"></label>
<br>
<img id="pic" alt="头像" src="">
<script>
    //----------获取头像-------------
    function jsGetUserGravatar() {
        pic.src = "";
        wanxiao.getUserGravatar(function (url) {
            pic.src = url;
            pic_url.innerHTML = url;
        });
    }
</script>

<br/><br/>

<input type="button" value="选择图片" onclick="openCamera1()"/>
<input type="button" value="选择图片(直接打开相册)" onclick="openCamera_1()"/>
<input type="button" value="选择图片(直接打开相机)" onclick="openCamera_2()"/>
<br/>
<img id="select_img" style="max-width: 300px" alt="" src="">
<script>
    //------------选择照片-------------------
    function openCamera1() {
        var jsonString = '{}';
        wanxiao.openCamera(jsonString);
    }

    //直接打开相册
    function openCamera_1() {
        var jsonString = '{"action":1,"isCrop":0, "ratio":1.5}';
        wanxiao.openCamera(jsonString);
    }

    //直接打开拍照
    function openCamera_2() {
        var jsonString = '{"action":2}';
        wanxiao.openCamera(jsonString);
    }

    Wanxiao.prototype.cameraPhotoCallBack = function (photoBase64Str) {
        console.log('-------图片回调----------');
        select_img.src = "data:image/png;base64," + photoBase64Str;
    };
</script>

<br/><br/>

<input type="button" value="分享..." onclick="shareToWanxiao();"/>
<br/>
<input type="button" value="分享到微信朋友圈" onclick="ShareWeixinCircle();"/>
<input type="button" value="分享到微信好友" onclick="ShareWeixin()"/>
<input type="button" value="分享到同学圈" onclick="ShareWanXiaoCircle();"/>
<br/>
<input type="button" value="分享到微博" onclick="ShareWeibo();"/>
<input type="button" value="分享到QQ" onclick="ShareQQ();"/>
<input type="button" value="分享到QQ空间" onclick="ShareQzone();"/>
<script>

    //-----------分享-------------------------

    var images = "[{\"url\":\"http://www.17wanxiao.com:80/campus/~/userPic/164\"},{\"url\":\"http://www.17wanxiao.com:80/campus/~/userPic/167\"}]";
    var imagejson = eval('(' + images + ')');

    function shareToWanxiao() {
        wanxiao.shareTo("-1", "sharetest", imagejson, "11", "11", "111", "222", "333");
    }

    function ShareWanXiaoCircle() {
        wanxiao.shareTo("0", "sharetest", imagejson, "11", "11", "111", "222", "333");
    }

    function ShareWeixin() {
        wanxiao.shareTo("1", "sharetest", imagejson, "http://www.baidu.com", "标题测试");
    }

    function ShareWeixinCircle() {
        wanxiao.shareTo("2", "sharetest", imagejson, "http://www.baidu.com", "标题测试");
    }

    function ShareWeibo() {
        wanxiao.shareTo("3", "sharetest", imagejson, "http://www.baidu.com", "标题测试");
    }

    function ShareQQ() {
        wanxiao.shareTo("4", "sharetest", imagejson, "http://www.baidu.com", "标题测试");
    }

    function ShareQzone() {
        wanxiao.shareTo("5", "sharetest", imagejson, "http://www.baidu.com", "标题测试");
    }

</script>

<br><br>

<input type="button" value="查询积分" onclick="callGetCredits()"/>
<input type="button" value="添加积分" onclick="callAddCredits()"/>
<input type="button" value="扣减积分" onclick="callReduceCredits()"/>
<script>

    //-------------积分----------------

    function callGetCredits() {
        var jsonString = '{"sign":"EA5CCB20","flag":"entertainmentSys","token":"3a459a5b-3dae-40a2-a942-ab27eb7758a3"}';
        wanxiao.getCredits(jsonString, callbackCredits);
    }

    function callAddCredits() {
        var jsonString = '{"sign":"0F3A9D39","desc":"娱乐系统赠送积分","flag":"entertainmentSys","token":"3a459a5b-3dae-40a2-a942-ab27eb7758a3","grade":"10"}';
        wanxiao.addCredits(jsonString, callbackCredits);
    }

    function callReduceCredits() {
        var jsonString = '{"sign":"5183BC22","desc":"娱乐系统消费积分","flag":"entertainmentSys","token":"3a459a5b-3dae-40a2-a942-ab27eb7758a3","grade":"5"}';
        wanxiao.reduceCredits(jsonString, callbackCredits);
    }

    function callbackCredits(restring) {
        if (restring != null && restring != "") {
            alert(restring);
        } else {
            alert("未获得调用结果");
        }
    }
</script>

<br>
<br>

<input type="button" value="调起支付收银台" onclick="callGetPayWay()"/>
<script>
    function callGetPayWay() {
        wanxiao.openPayWay('{"acccode":"301002","accdescrp":"充值10元","app_id":"132","gateway_id":"","gateway_type":"","merchant_olid":24,"olid":385,"order_no":"2015111300000043","sign":"424039EA66219635","total_fee":"1000","ver":"1.0"}', function (result) {
            alert(result);
        });
    }
</script>
<br>
<br>

<table>
    <tr>
        <td>sign:</td>
        <td><input id="s" type="text" value="2B5A2EC1"/></td>
    </tr>
    <tr>
        <td>toUserId:</td>
        <td><input id="u" type="text" value="21626"/></td>
    </tr>
</table>
<input type="button" value="插件消息推送-Html" onclick="pushHtml()"/>
<label id="r"></label>
<script>
    function pushHtml() {
        //var param='{"sign":"60FE8BDC","message":"测试推送内容","title":"推送标题","flag":"entertainmentSys","versionname":"v1.0","token":"7d444f84-2389-4f31-adf3-79f22dba8836","toUserId":134320,"param":"{param1:\'param1Val\', param2:\'param2Val\'}","appcode":"ylxt","versioncode":"1"}';
        var sign = document.getElementById("s").value;
        var toUserId = document.getElementById("u").value;

        var param = '{"sign":"'
            + sign
            + '","message":"测试推送内容","title":"推送标题","flag":"entertainmentSys","versionname":"v1.0","token":"7d444f84-2389-4f31-adf3-79f22dba8836","toUserId":'
            + toUserId
            + ',"param":"{param1:\'param1Val\', param2:\'param2Val\'}","appcode":"ylxt","versioncode":"1"}';
        document.getElementById("r").innerHTML = param;
        wanxiao.sendRemoteNotification(param, function (result) {
            alert(result);
        });
    }
</script>

<br/>
<br/>
<table>
    <tr>
        <td>sign:</td>
        <td><input id="s1" type="text" value="7682F96D"/></td>
    </tr>
    <tr>
        <td>toUserId:</td>
        <td><input id="u1" type="text" value="21626"/></td>
    </tr>
    <tr>
        <td>param:</td>
        <td><input id="p1" type="text"
                   value="{param1:'ylxt_activity1', param2:'ylxt_activity2'}"/></td>
    </tr>
</table>
<input type="button" value="插件消息推送-activity" onclick="pushActivity()"/>
<label id="r1"></label>
<script>
    function pushActivity() {
        //{"sign":"7682F96D","message":"测试推送内容ylxt_activity","title":"推送标题ylxt_activity",
        //	"flag":"ylxt_activity","versionname":"v1.0","token":"9584b58c-8a5e-4a60-b5f1-da789cf9cf14",
        //"toUserId":21626,"param":"{param1:'ylxt_activity1', param2:'ylxt_activity2'}",
        //"appcode":"ylxt_activity","versioncode":"1"}
        var sign = document.getElementById("s1").value;
        var toUserId = document.getElementById("u1").value;
        var param = document.getElementById("p1").value;
        var param = '{"sign":"'
            + sign
            + '","message":"测试推送内容ylxt_activity","title":"推送标题ylxt_activity","flag":"ylxt_activity","versionname":"v1.0","token":"9584b58c-8a5e-4a60-b5f1-da789cf9cf14","toUserId":'
            + toUserId
            + ',"param":"'
            + param
            + '","appcode":"ylxt_activity","versioncode":"1"}';
        document.getElementById("r1").innerHTML = param;
        wanxiao.sendRemoteNotification(param, function (result) {
            alert(result);
        });
    }
</script>

<br/>
<br/>

<input type="button" value="说两句(聊天)" onclick="openChat()"/>
<script>
    function openChat() {
        wanxiao.openChat("123", "1232", "asdfasdfasd", "ww32", function (result) {
            alert(result);
        });
        //window.wanxiao_chat.executeBindMethod("getChat", '{"toId":123, "fromId":1232, "sign":"asdfasdfasd", "flag":"ww32"}');
    }
</script>

<br/><br/>

<input type="button" value="创建3个菜单" onclick="createMenu()"/>
<input type="button" value="创建1个菜单" onclick="createMenu1()"/>
<input type="button" value="创建1个菜单" onclick="createMenu11()"/>
<script>
    //----------创建菜单-----------------------
    function getMenuObject(title, icon, url) {
        var m = new Object();
        m.title = title;
        m.icon = icon;
        m.url = url;
        return m;
    }

    createMenu11();

    function createMenu() {
        var arrayObj = [];
        arrayObj[0] = getMenuObject("百度", "http://www.baidu.com/favicon.ico", "http://www.baidu.com");
        arrayObj[1] = getMenuObject("网易", "http://www.163.com/favicon.ico", "http://www.163.com");
        arrayObj[2] = getMenuObject("扫一扫", "http://www.ithome.com/favicon.ico", "javascript:scan()");

        var jsonStr = JSON.stringify(arrayObj);
        wanxiao.setMenu(jsonStr, function (result) {
            alert("setMenu:---" + result);
        });
    }

    function createMenu11() {
        var menuJson = [{"title": "扫一扫", "icon": "http://www.163.com/favicon.ico", "url": "javascript:scan()"}];
        var jsonStr = JSON.stringify(menuJson);
        wanxiao.setMenu(jsonStr, function (result) {
        });
    }

    function createMenu1() {
        var arrayObj = [];

        arrayObj[0] = getMenuObject("百度", "https://www.easyicon.net/api/resizeApi.php?id=1270604&size=72", "http://www.baidu.com");

        var jsonStr = JSON.stringify(arrayObj);

        wanxiao.setMenu(jsonStr, function (result) {
        });
    }
</script>

<br/><br/>
新菜单设置
<br/>
<input type="button" value="创建3个菜单" onclick="createMenuNew()"/>
<input type="button" value="创建1个菜单" onclick="createMenu1New()"/>
<input type="button" value="显示菜单" onclick="showMenu()"/>
<input type="button" value="隐藏菜单" onclick="hideMenu()"/>
<script>
    function showMenu() {
        wanxiao.showMenu();
    }

    function hideMenu() {
        wanxiao.hideMenu();
    }

    var menu1 = {"id": "10", "title": "分享微信", "icon": "http://3.kimimagic01.sinaapp.com/password.png"};
    var menu2 = {"id": "20", "title": "分享朋友圈", "icon": "http://3.kimimagic01.sinaapp.com/record.png"};
    var menu3 = {"id": "30", "title": "分享同学圈", "icon": "http://3.kimimagic01.sinaapp.com/78@3x.png"};

    function createMenuNew() {
        var menu = {"data": [menu1, menu2, menu3]};
        wanxiao.setMenu1(menu, function (id) {
            switch (parseInt(id)) {
                case 10:
                    ShareWeixin();
                    break;
                case 20:
                    ShareWeixinCircle();
                    break;
                case 30:
                    ShareWanXiaoCircle();
                    break;
                default:
                    break;

            }
        });
    }

    function createMenu1New() {
        var menu = {"data": [menu3]};
        wanxiao.setMenu1(menu, function (id) {
            alert(id);
        });
    }
</script>

<br/><br/>
<input type="button" value="扫描条码" onclick="scan()"/>
<label id="barcode"></label>
<script>
    function scan() {
        wanxiao.scanBarcode(function (result) {
            barcode.innerHTML = result;
        });
    }
</script>

<br/><br/>

<input type="button" value="摇一摇" onclick="startShake()"/>
<script>
    function startShake() {
        wanxiao.shake(function () {
            alert("跟我一起摇摆")
        });
    }
</script>

<br/><br/>

<input type="button" value="图片浏览" onclick="openImageView()"/>
<script>
    function openImageView() {
        var arrayObj = [];
        arrayObj[0] = "http://www.baidu.com/favicon.ico";
        arrayObj[1] = "http://www.163.com/favicon.ico";
        arrayObj[2] = "http://www.ithome.com/favicon.ico";
        arrayObj[3] = "http://192.168.157.246/img/1.gif";
        arrayObj[4] = "http://192.168.157.246/img/2.jpg";
        var jsonStr = JSON.stringify(arrayObj);
        var index = 2;
        wanxiao.openImageView(jsonStr, index, function (result) {
            alert(result);
        });
    }
</script>

<br/><br/>

<input type="button" value="获取网络状态" onclick="getNetwork()"/>
<script>
    function getNetwork() {
        wanxiao.getNetworkStatus(function (result) {
            alert(result);
        });
    }
</script>

<br/><br/>

<input type="button" value="选择图片(selectImage)" onclick="select_image1()"/>
<input type="button" value="选择图片(selectImage1不裁剪)" onclick="select_image2()"/>
<input type="button" value="选择图片(selectImage1裁剪)" onclick="select_image3()"/>
<br>
<img style="max-width: 300px" id="select_image" alt="图片" src="">
<script>
    function select_image1() {
        wanxiao.selectImage(function (result) {
            select_image.src = "data:image/png;base64," + result;
        });
    }

    function select_image2() {
        var jsonString = '{"isCrop":0, "ratio":1.5}';
        wanxiao.selectImage1(jsonString, function (result) {
            select_image.src = "data:image/png;base64," + result;
        });
    }

    function select_image3() {
        var jsonString = '{"isCrop":1, "ratio":1.5}';
        wanxiao.selectImage1(jsonString, function (result) {
            select_image.src = "data:image/png;base64," + result;
        });
    }
</script>

<br/>
<br/>

<input id="title_text" type="text" value=""/>
<input type="button" value="设置标题" onclick="setTitle()"/>
<script>
    function setTitle() {
        wanxiao.setTitle(title_text.value, function (result) {
            alert(result);
        });
    }
</script>

<br/><br/>

<input id="config_text" type="text" value=""/>
<input type="button" value="设置配置" onclick="setConfig()"/>
<input type="button" value="获取配置项" onclick="getConfig()"/>
<script>
    function setConfig() {
        wanxiao.setConfig("key1106", config_text.value);
    }

    function getConfig() {
        wanxiao.getConfig("key1106", function (result) {
            alert(result);
        });
    }
</script>

<br/><br/>

<input type="button" value="获取token" onclick="getTokenInfo()"/>
<script>
    function getTokenInfo() {
        wanxiao.getToken(function (result) {
            alert(result);
        });
    }
</script>

<br/><br/>

<input type="button" value="获得用户信息" onclick="callUserInfo()"/>
<script>
    function callUserInfo() {
        wanxiao.getUserJsonValue(function (result) {
            alert(result)
        });
    }
</script>

<br/><br/>

<input type="button" value="关闭webapp" onclick="closeWebapp()"/>
<script>
    function closeWebapp() {
        wanxiao.closeAppWeb();
    }
</script>

<br/><br/>

<input type="button" value="调用直播" onclick="openPlay()"/>
<script>
    function openPlay() {
        wanxiao.NCPStartTalkFun("2", "123", "444444");
    }
</script>

<br/><br/>
<input type="button" value="获取通知状态" onclick="getNotifyStatus()"/>
<input type="button" value="打开通知设置" onclick="openNotifySetting()"/>
<script>
    function getNotifyStatus() {
        wanxiao.getNotificationStatus(function (result) {
            alert(result)
        })
    }

    function openNotifySetting() {
        wanxiao.openNotificationSetting();
    }
</script>
<br/>
<br/>
<!--<input type="button" value="发帖scheme加回调" onclick="publishSchemeCallback()">-->
<a href="wanxiao://17wanxiao.com?page=publishFriendCirclePage&data={content:'scheme传入的内容'}">发帖(测试统一回调)</a>
<script>
    wanxiao.commonCallback(function (result) {
        alert(result);
    });
</script>

<br/><br/>

<label>roomId：<input type="text" id="roomId" value="12345"></label>
<button onclick="joinCall()">视频通话</button>
<br/>
<label id="result"></label>
<script>
    function joinCall() {
        var rId = roomId.value;

        if (!rId) {
            alert("请输入roomId");
            return;
        }

        result.innerHTML = "";
        wanxiao.videoCall(rid, function () {
            result.innerHTML = "通话结束";
        })
    }
</script>

<br/><br/>

<input id="package_name" type="text" value="com.huawei.wallet"/>
<input type="button" value="获取App版本信息" onclick="getAppVersionInfo()"/>
<script>
    function getAppVersionInfo() {
        wanxiao.getAppVersionInfo(package_name.value, function (result) {
            alert(result);
        })
    }
</script>

<br/><br/>

广告类型：<input id="advert_type" type="text" value="1"/>
<div style="height: 5px"></div>
广告位置：<input id="advert_position" type="text" value="2"/>
<div style="height: 7px"></div>
<input type="button" value="请求广告" onclick="requestAd()"/>
<input type="button" value="展示广告" onclick="showAd()"/>
<input type="button" value="请求并展示广告" onclick="requestAndShowAd()"/>
<script>
    function requestAd() {
        wanxiao.requestAdvert({
            adType: advert_type.value,
            adPosition: advert_position.value
        }, function (result) {
            alert(result);
        })
    }

    function showAd() {
        wanxiao.showAdvert({
            adType: advert_type.value,
            adPosition: advert_position.value
        }, function (result) {
            alert(result);
        })
    }

    function requestAndShowAd() {
        wanxiao.requestAndShowAdvert({
            adType: advert_type.value,
            adPosition: advert_position.value
        }, function (result) {
            alert(result);
        })
    }
</script>

<br/><br/>

<input type="button" value="H5透明状态栏" onclick="statusBarTransparent()">
<input type="button" value="H5隐藏状态栏" onclick="statusBarHide()">

<script>
    function statusBarTransparent() {
        wanxiao.openNewWebview("http://192.168.121.85/blog/wmxy/h5_title_bar.html?NCPNavBarAlpha=0", "slide", "show");
    }

    function statusBarHide(url, status) {
        wanxiao.openNewWebview("http://192.168.121.85/blog/wmxy/h5_title_bar.html?NCPNavBarState=hide", "slide", "hide");

    }
</script>

<br/><br/>

<label>图片(base64)</label>
<input type="button" value="保存图片" onclick="saveBase64Img()">
<input type="button" value="下载图片" onclick="downloadImage()">
<br>
<img style="width: 200px;height: 350px" id="base64Img"
     src=""/>
<br>
<script>
    function saveBase64Img() {
        // alert('asdf')
        wanxiao.saveImgInfo(base64Img.src, function (result) {
            alert(result)
        })
    }

    function downloadImage() {
        wanxiao.saveImgInfo('http://192.168.121.85/image/big.jpg', function (result) {
            alert(result)
        })
    }
</script>


</body>
</html>
